package tothreedesignmodel.iterator;

import lombok.Data;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lzhphantom
 * @description
 * @date 创建于 23:38 2020/8/1
 * @modified
 */
@Data
public class ConcreteAggregate implements Aggregate {
    private List<Object> list = new ArrayList<>();

    @Override
    public void add(Object obj) {
        list.add(obj);
    }

    @Override
    public void remove(Object obj) {
        list.remove(obj);
    }

    @Override
    public Iterator<Object> getIterator() {
        return new ConcreteIterator<>(list);
    }

    public static void main(String[] args) {
        Aggregate ag = new ConcreteAggregate();
        ag.add("中山大学");
        ag.add("华南理工");
        ag.add("韶关学院");
        System.out.print("聚合的内容有：");
        Iterator<Object> it = ag.getIterator();
        while (it.hasNext()) {
            Object ob = it.next();
            System.out.print(ob.toString() + "\t");
        }
        Object ob = it.first();
        System.out.println();
        System.out.println("First：" + ob.toString());
    }
}
